package com.bnz.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * elasticsearch配置类
 */
@Configuration // 配置类
@Data // 创建get，set(需要)
@ConfigurationProperties(prefix = "elasticsearch") // 获取application.yml里elasticsearch定义的参数
public class ElasticSearchConfig {
    // 主机
    private String host; // 会获取引入application.yml的elasticsearch的host
    // 端口
    private Integer port; // 会获取引入application.yml的elasticsearch的port

    @Bean
    RestHighLevelClient elasticsearchRestHighLevelClient() {
        RestClientBuilder builder = RestClient.builder(new HttpHost(host, port)); // 地址，端口
        return new RestHighLevelClient(builder);
    }
}
